<template>
  <div
    class="map"
    v-loading="loading"
    element-loading-text="影像正加载中..."
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)"
  >
    <div v-for="map in maps" :key="map.id" class="grid-content">
      <div
        :class="selected == map.id ? 'map-item selected' : 'map-item'"
        @click="handleChangeBasemap(map)"
      >
        <img :src="map.img" width="78" height="78" />
        <div class="title">{{ map.name }}</div>
      </div>
    </div>
  </div>
</template>

<script>
import { changeBasemap } from "../profile";
import db from "../../../utils/localstorage";

export default {
  data() {
    return {
      selected: 0,
      loading: false,
      maps: [],
    };
  },
  mounted() {
    console.log(config);
    this.maps = config.maps;
  },
  methods: {
    handleChangeBasemap(map) {
      let me = this;
      if (me.selected === map.id || me.loading) {
        return;
      }
      me.selected = map.id;
      me.loading = true;
      changeBasemap(map).then(() => {
        me.loading = false;
      });

      let setting = db.get("setting");
      setting['basemap'] = map.name;
      db.save("setting", setting);

      // let imagery = earth.layersManager.getImageryProvider(map);
      // imagery && imagery.readyPromise.then(ret => {
      //
      //     if(ret) {
      //         viewer.imageryLayers.remove(viewer.imageryLayers.get(0));
      //         viewer.imageryLayers.addImageryProvider(imagery, 0);
      //     }
      // })
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/assets/styles/index.scss";

.map {
  display: flex;
  flex-wrap: wrap;
  padding: 5px;

  .grid-content {
    width: 100px;
    height: 80px;
    margin-bottom: 20px;

    display: flex;
    justify-content: center;
    align-items: center;

    .map-item {
      width: 80px;
      height: 80px;
      position: relative;
      box-sizing: border-box;
      border: 1px solid rgba(255, 255, 0, 0);
      cursor: pointer;

      .title {
        font-size: 12px;
        text-align: center;
        position: absolute;
        bottom: 0;
        width: 78px;
        overflow: hidden;
        background-color: rgb(68 68 68 / 75%);
        color: #fff;
      }
    }
    .map-item:hover {
      border: 1px solid rgb(0, 159, 170);

      .title {
        color: rgb(0, 159, 170);
      }
    }

    .selected {
      color: rgb(0, 140, 255);
      border: 1px solid rgb(0, 140, 255);

      .title {
        color: rgb(0, 140, 255);
      }
    }
  }
}
</style>